package com.example.yunbiji0314.controller;

import com.example.yunbiji0314.pojo.Good;
import com.example.yunbiji0314.service.GoodService;
import com.example.yunbiji0314.util.Code;
import com.example.yunbiji0314.util.Result;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/good")
public class GoodController {

    @Autowired
    private GoodService goodService;
    @PostMapping("/zenggood")
    @ApiModelProperty(value = "添加文章")
    public Result zenggood(@RequestBody Good good) {
        System.out.println(good);
        int i = goodService.zenggood(good);
        if(i>0) {
            return new Result(Code.SAVE_OK,"添加成功");
        } else {
            return new Result(Code.SAVE_ERR,"添加失败");
        }
    }

    @RequestMapping("/findByUserId/{id}")
    @ApiModelProperty(value = "根据用户id查询商品")
    public Result findByUserId(@PathVariable Integer id) {
        System.out.println(id);
        List<Map> list = goodService.findByUserId(id);
        if (list != null) {
            return new Result(Code.GET_OK, list, "查询成功");
        } else {
            return new Result(Code.GET_ERR, "查询失败");
        }
    }
}

